Querying the hostname of the server

Querying the hostname of the server

am 30.04.2010 15:33:13 von maxottovonstirlitz

--001485e8cb6ff269bc0485744859
Content-Type: text/plain; charset=UTF-8

Hi,

I have a number of PostgreSQL servers which I often access through ssh
tunnel with Pgadmin3. I would like to double check which one I have landed
on (if the tunnel is really configured the way I want). Is there a way to
query the hostname from the catalogs?

Thanks
Peter

--001485e8cb6ff269bc0485744859
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

pan class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; fon=
t-size: 14px; border-collapse: collapse; ">Hi,


I have a =
number of PostgreSQL servers which I often access through ssh tunnel with P=
gadmin3. I would like to double check which one I have landed on (if the tu=
nnel is really configured the way I want). Is there a way to query the host=
name from the catalogs?


Thanks
Peter


--001485e8cb6ff269bc0485744859--

Re: Querying the hostname of the server

am 30.04.2010 16:14:04 von reedstrm

On Fri, Apr 30, 2010 at 03:33:13PM +0200, P=E9ter Kov=E1cs wrote:
> Hi,
>=20
> I have a number of PostgreSQL servers which I often access through ssh
> tunnel with Pgadmin3. I would like to double check which one I have lan=
ded
> on (if the tunnel is really configured the way I want). Is there a way =
to
> query the hostname from the catalogs?

Hmm, that's a bit tricky, since I assume you're using a local db
connection inside the tunnel, so inet_server_addr() probably returns
null. If you're talking unix/linux machines, then /etc/hostname _should_
have the current hostname in it, so:

create temp table foo (t text);
copy foo from '/etc/hostname';
select * from foo;
drop table foo;

Should work.

Ross
--=20
Ross Reedstrom, Ph.D. reedstrm@rice.edu
Systems Engineer & Admin, Research Scientist phone: 713-348-6166
The Connexions Project http://cnx.org fax: 713-348-3665
Rice University MS-375, Houston, TX 77005
GPG Key fingerprint =3D F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BED=
E

--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

Re: Querying the hostname of the server

am 30.04.2010 16:20:55 von Kevin Grittner

"Ross J. Reedstrom" wrote:

> If you're talking unix/linux machines, then /etc/hostname _should_
> have the current hostname in it

If not, check for /etc/HOSTNAME -- some distributions do that.

-Kevin

--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

Re: Querying the hostname of the server

am 30.04.2010 16:33:38 von maxottovonstirlitz

--00148531a52b02479204857521c8
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Thank you, Ross!

inet_server_addr() returns the correct IP address in this case. I am not
sure why... The tunnel goes through at least one port-forwarding node, but =
I
am not sure this makes postgresql see the connection any less local.

Thanks
Peter

On Fri, Apr 30, 2010 at 4:14 PM, Ross J. Reedstrom wrote=
:

> On Fri, Apr 30, 2010 at 03:33:13PM +0200, Péter Kovács wrote:
> > Hi,
> >
> > I have a number of PostgreSQL servers which I often access through ssh
> > tunnel with Pgadmin3. I would like to double check which one I have
> landed
> > on (if the tunnel is really configured the way I want). Is there a way =
to
> > query the hostname from the catalogs?
>
> Hmm, that's a bit tricky, since I assume you're using a local db
> connection inside the tunnel, so inet_server_addr() probably returns
> null. If you're talking unix/linux machines, then /etc/hostname _should_
> have the current hostname in it, so:
>
> create temp table foo (t text);
> copy foo from '/etc/hostname';
> select * from foo;
> drop table foo;
>
> Should work.
>
> Ross
> --
> Ross Reedstrom, Ph.D. reedstrm@rice.edu
> Systems Engineer & Admin, Research Scientist phone: 713-348-6166
> The Connexions Project http://cnx.org fax: 713-348-3665
> Rice University MS-375, Houston, TX 77005
> GPG Key fingerprint =3D F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BED=
E
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
>

--00148531a52b02479204857521c8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Th=
ank you, Ross!


"font-family: arial, sans-serif; font-size: 14px; border-collapse: collapse=
; ">inet_server_addr() returns the correct IP address in this case. I am no=
t sure why... The tunnel goes through at least one port-forwarding node, bu=
t I am not sure this makes postgresql see the connection any less local. pan>

if; font-size: 14px; border-collapse: collapse; ">
an class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; bord=
er-collapse: collapse; ">Thanks

s=3D"Apple-style-span" style=3D"border-collapse: collapse; ">Peter
n>

On Fri, Apr 30, 2010 at 4:14 =
PM, Ross J. Reedstrom < ..edu">reedstrm@rice.edu> wrote:

x #ccc solid;padding-left:1ex;">On Fri, Apr 30, 2010 at 03:33:13PM +0200, P=
éter Kovács wrote:

> Hi,

>

> I have a number of PostgreSQL servers which I often access through ssh=


> tunnel with Pgadmin3. I would like to double check which one I have la=
nded

> on (if the tunnel is really configured the way I want). Is there a way=
to

> query the hostname from the catalogs?



Hmm, that's a bit tricky, since I assume you're using a local db >
connection inside the tunnel, so inet_server_addr() probably returns

null. If you're talking unix/linux machines, then /etc/hostname _should=
_

have the current hostname in it, so:



create temp table foo (t text);

copy foo from '/etc/hostname';

select * from foo;

drop table foo;



Should work.



Ross

--

Ross Reedstrom, Ph.D.               =C2=
=A0                 to:reedstrm@rice.edu">reedstrm@rice.edu

Systems Engineer & Admin, Research Scientist       =C2=
=A0phone: 713-348-6166

The Connexions Project       t=3D"_blank">http://cnx.org            fa=
x: 713-348-3665

Rice University MS-375, Houston, TX 77005

GPG Key fingerprint =3D F023 82C8 9B0E 2CC6 0D8E  F888 D3AE 810E 88F0 =
BEDE



--

Sent via pgsql-admin mailing list ( ..org">pgsql-admin@postgresql.org)

To make changes to your subscription:

">http://www.postgresql.org/mailpref/pgsql-admin




--00148531a52b02479204857521c8--

Re: Querying the hostname of the server

am 30.04.2010 16:43:49 von Glyn Astill

--- On Fri, 30/4/10, Ross J. Reedstrom wrote:

> > Hi,
> >=20
> > I have a number of PostgreSQL servers which I often
> access through ssh
> > tunnel with Pgadmin3. I would like to double check
> which one I have landed
> > on (if the tunnel is really configured the way I
> want). Is there a way to
> > query the hostname from the catalogs?
>=20
> Hmm, that's a bit tricky, since I assume you're using a
> local db
> connection inside the tunnel, so inet_server_addr()
> probably returns
> null. If you're talking unix/linux machines, then
> /etc/hostname _should_
> have the current hostname in it, so:
>=20
> create temp table foo (t text);
> copy foo from '/etc/hostname';
> select * from foo;
> drop table foo;
>=20
> Should work.
>=20

Or you could do something like:

CREATE OR REPLACE FUNCTION hostname()
RETURNS text AS
$BODY$
$host =3D `hostname`;
return $host;
$BODY$
LANGUAGE 'plperlu';






--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

Re: Querying the hostname of the server

am 30.04.2010 17:01:26 von Achilleus Mantzios

Yes, nice and simple.

I just did this in C and it works ok!

hostname.c
==================== =====3D=
==================

#include
#include "postgres.h"
#include "utils/elog.h"
#include "utils/palloc.h"
#include "storage/bufpage.h"
#define MAX_HOST_SIZE 200

PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(hostname);
Datum hostname(PG_FUNCTION_ARGS);

Datum
hostname(PG_FUNCTION_ARGS)
{
int len;
char buf[MAX_HOST_SIZE + 1];
text *result;

gethostname(buf,MAX_HOST_SIZE);
len =3D strlen(buf);
//elog(NOTICE, "hostname=3D%s\n",buf);
result=3D(text *)palloc(len + VARHDRSZ);
SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result),buf,strlen(buf));
PG_RETURN_POINTER(result);
}


Makefile
==================== =====3D=
==================
MODULE_big =3D hostname
OBJS =3D hostname.o

ifdef USE_PGXS
PG_CONFIG =3D pg_config
PGXS :=3D $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir =3D /var/lib/pgsql/src/Ccode/hostname
top_builddir =3D /usr/local/src/postgresql-8.3.3
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif


hostname.sql
==================== =====3D=
==================== =====3D
CREATE OR REPLACE FUNCTION hostname() RETURNS text
AS '$libdir/hostname', 'hostname'
LANGUAGE c IMMUTABLE STRICT;


Στις Friday 30 April 2010 17:43:49 ο/η Glyn A=
still έγραψε:
> --- On Fri, 30/4/10, Ross J. Reedstrom wrote:
>=20
> > > Hi,
> > >=20
> > > I have a number of PostgreSQL servers which I often
> > access through ssh
> > > tunnel with Pgadmin3. I would like to double check
> > which one I have landed
> > > on (if the tunnel is really configured the way I
> > want). Is there a way to
> > > query the hostname from the catalogs?
> >=20
> > Hmm, that's a bit tricky, since I assume you're using a
> > local db
> > connection inside the tunnel, so inet_server_addr()
> > probably returns
> > null. If you're talking unix/linux machines, then
> > /etc/hostname _should_
> > have the current hostname in it, so:
> >=20
> > create temp table foo (t text);
> > copy foo from '/etc/hostname';
> > select * from foo;
> > drop table foo;
> >=20
> > Should work.
> >=20
>=20
> Or you could do something like:
>=20
> CREATE OR REPLACE FUNCTION hostname()
> RETURNS text AS
> $BODY$
> $host =3D `hostname`;
> return $host;
> $BODY$
> LANGUAGE 'plperlu';
>=20
>=20
>=20
>=20
>=20
>=20



--=20
Achilleas Mantzios

--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

Re: Querying the hostname of the server

am 01.05.2010 17:32:31 von Julio Leyva

--_1c9c11df-2871-4f4d-92f0-964df596e3b1_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


I think you can do something like that as a postgresql user

su - postgres
=20
psql -c "\! uname -n"

or actually you can do that inside of any sql statement

psql=20
\!uname -n




> Date: Fri=2C 30 Apr 2010 09:14:04 -0500
> From: reedstrm@rice.edu
> To: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] Querying the hostname of the server
>=20
> On Fri=2C Apr 30=2C 2010 at 03:33:13PM +0200=2C P=E9ter Kov=E1cs wrote:
> > Hi=2C
> >=20
> > I have a number of PostgreSQL servers which I often access through ssh
> > tunnel with Pgadmin3. I would like to double check which one I have lan=
ded
> > on (if the tunnel is really configured the way I want). Is there a way =
to
> > query the hostname from the catalogs?
>=20
> Hmm=2C that's a bit tricky=2C since I assume you're using a local db
> connection inside the tunnel=2C so inet_server_addr() probably returns
> null. If you're talking unix/linux machines=2C then /etc/hostname _should=
_
> have the current hostname in it=2C so:
>=20
> create temp table foo (t text)=3B
> copy foo from '/etc/hostname'=3B
> select * from foo=3B
> drop table foo=3B
>=20
> Should work.
>=20
> Ross
> --=20
> Ross Reedstrom=2C Ph.D. reedstrm@rice.edu
> Systems Engineer & Admin=2C Research Scientist phone: 713-348-6166
> The Connexions Project http://cnx.org fax: 713-348-3665
> Rice University MS-375=2C Houston=2C TX 77005
> GPG Key fingerprint =3D F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BED=
E
>=20
> --=20
> Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
=

--_1c9c11df-2871-4f4d-92f0-964df596e3b1_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable






I think you can do something like that as a postgresql user

su - pos=
tgres
 =3B
psql -c "\! uname -n"

or actually you can do th=
at inside of any sql statement

psql
\!uname -n



r>>=3B Date: Fri=2C 30 Apr 2010 09:14:04 -0500
>=3B From: reedstrm@r=
ice.edu
>=3B To: pgsql-admin@postgresql.org
>=3B Subject: Re: [AD=
MIN] Querying the hostname of the server
>=3B
>=3B On Fri=2C Apr=
30=2C 2010 at 03:33:13PM +0200=2C P=E9ter Kov=E1cs wrote:
>=3B >=3B=
Hi=2C
>=3B >=3B
>=3B >=3B I have a number of PostgreSQL ser=
vers which I often access through ssh
>=3B >=3B tunnel with Pgadmin3=
.. I would like to double check which one I have landed
>=3B >=3B on =
(if the tunnel is really configured the way I want). Is there a way to
&=
gt=3B >=3B query the hostname from the catalogs?
>=3B
>=3B Hmm=
=2C that's a bit tricky=2C since I assume you're using a local db
>=3B=
connection inside the tunnel=2C so inet_server_addr() probably returns
=
>=3B null. If you're talking unix/linux machines=2C then /etc/hostname _s=
hould_
>=3B have the current hostname in it=2C so:
>=3B
>=
=3B create temp table foo (t text)=3B
>=3B copy foo from '/etc/hostnam=
e'=3B
>=3B select * from foo=3B
>=3B drop table foo=3B
>=3B =

>=3B Should work.
>=3B
>=3B Ross
>=3B --
>=3B R=
oss Reedstrom=2C Ph.D. reedstrm@rice.edu >>=3B Systems Engineer &=3B Admin=2C Research Scientist phone: =
713-348-6166
>=3B The Connexions Project http://cnx.org =
fax: 713-348-3665
>=3B Rice University MS-375=2C Houston=2C TX 77005=

>=3B GPG Key fingerprint =3D F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E=
88F0 BEDE
>=3B
>=3B --
>=3B Sent via pgsql-admin mailing =
list (pgsql-admin@postgresql.org)
>=3B To make changes to your subscri=
ption:
>=3B http://www.postgresql.org/mailpref/pgsql-admin
=

=

--_1c9c11df-2871-4f4d-92f0-964df596e3b1_--